//
//  MyDemoTransitionVC.m
//  HDTransitonDemo
//
//  Created by mac on 2017/5/19.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "MyDemoTransitionVC.h"
#import "MyDemoPresentVC.h"

#import "HD_Lida_AnimatonBubble.h"
#import "HD_Lida_PresentTransition.h"

@interface MyDemoTransitionVC ()<UIViewControllerTransitioningDelegate>{
    
    UIButton *button;
}



@end

@implementation MyDemoTransitionVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self prepareBubble];
}

- (void)prepareBubble {
    self.view.backgroundColor = [UIColor redColor];
    
    button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake((self.view.frame.size.width - 80) / 2,
                              self.view.frame.size.height - 80 - 64,
                              80,
                              80);
    [self.view addSubview:button];
    [button setTitle:@"+" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button.backgroundColor = [UIColor purpleColor];
    button.titleLabel.font = [UIFont boldSystemFontOfSize:60];
    
    button.layer.cornerRadius = 40;
    [button addTarget:self action:@selector(actionBubble:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)actionBubble:(UIButton *)sender {
    MyDemoPresentVC *presentedVC = [[MyDemoPresentVC alloc] init];
    
    // 设置transitioningDelegate, 然后在其中实现协议方法即可.
    presentedVC.transitioningDelegate = self;
    [self presentViewController:presentedVC animated:YES completion:nil];
}

#pragma mark - <UIViewControllerTransitioningDelegate>

- (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {
    
    //将需要的动画添加在这里即可
    switch (_demoType) {
        case DemoViewControllerTransitionTypeBubble:
        {
            // Bubble
            HD_Lida_AnimatonBubble *bubbleTransition = [[HD_Lida_AnimatonBubble alloc] init];
            bubbleTransition.bubbleCenter = button.center;
            bubbleTransition.animatorTransitionType = kAnimatorTransitionTypePresent;
            return bubbleTransition;
        }
        default:
            break;
    }
    
    HD_Lida_PresentTransition *presentTransition = [[HD_Lida_PresentTransition alloc] init];
    presentTransition.animatorTransitionType = kAnimatorTransitionTypePresent;
    return presentTransition;
}

- (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
    switch (_demoType) {
                case DemoViewControllerTransitionTypeBubble:
        {
            // Bubble
            HD_Lida_AnimatonBubble *bubbleTransition = [[HD_Lida_AnimatonBubble alloc] init];
            bubbleTransition.animatorTransitionType = kAnimatorTransitionTypeDismiss;
            bubbleTransition.bubbleCenter = button.center;
            return bubbleTransition;
        }
                default:
            break;
    }
    
    HD_Lida_PresentTransition *presentTransition = [[HD_Lida_PresentTransition alloc] init];
    presentTransition.animatorTransitionType = kAnimatorTransitionTypeDismiss;
    return presentTransition;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
